
---@class CustomRoot
CustomRoot = {}

function CustomRoot:Init()
    self.speed = 4;
    local transA = CS.UnityEngine.GameObject.Find("TestPlayer").transform;
    ---@type UnityEngine.CharacterController
    self._controller = transA:GetComponent(typeof(CS.UnityEngine.CharacterController));
    self.agentB = Custom_Agent.new();
    local transB = CS.UnityEngine.GameObject.Find("TestEnemy").transform;
    self.agentB.dataMap:SetGameData(ECustomDataName.SelfTrans,transB)
    self.agentB.dataMap:SetGameData(ECustomDataName.TargetTrans,transA)
    self.agentB.dataMap:SetGameData(ECustomDataName.OriginalPos,transB.position);
    self.agentB.agentState:Set(ECustomStateKey.Can_move,true)
    UpdateManager:AddUpdate(self.fixdUpdate,self)
end

function CustomRoot:fixdUpdate()
    self.agentB:FrameFun();

    if CS.UnityEngine.Input.GetKey(CS.UnityEngine.KeyCode.W) then
        self._controller:SimpleMove(CS.UnityEngine.Vector3.forward * self.speed);
    end
    if CS.UnityEngine.Input.GetKey(CS.UnityEngine.KeyCode.S) then
        self._controller:SimpleMove(CS.UnityEngine.Vector3.back * self.speed);
    end
    if CS.UnityEngine.Input.GetKey(CS.UnityEngine.KeyCode.A) then
        self._controller:SimpleMove(CS.UnityEngine.Vector3.left * self.speed);
    end
    if CS.UnityEngine.Input.GetKey(CS.UnityEngine.KeyCode.D) then
        self._controller:SimpleMove(CS.UnityEngine.Vector3.right * self.speed);
    end
end